<?php
namespace Manage\Controller;
use Common\Controller\ManageBaseController;
use Think\Model;
use Common\Model\ArticleModel;
use Common\Model\MemberModel;



class TaobaoController extends ManageBaseController{
	
	public function lists($ajax=null,$status=null,$page=null,$rows=null,$type = NULL) {
		$map = array();
		$map['status'] = array('EGT',0); //默认查询状态为未删除的数据
		if ($page <= 0) {
			$page = 1;
		}
		if ($rows > 0) {
			$listRows = $rows;
		}else {
			$listRows = C('LIST_ROWS') > 0 ? C('LIST_ROWS') : 10;
		}
		
		/******************/
		if ($ajax==='y') {
			$model = new Model('Taobao');
			$member = new MemberModel();
			$total = $model->where($map)->count(); //总记录数
			$list = $model->where($map)->order('createtime desc')->page("$page,$listRows")->select();
			
			//list数据处理
			foreach ($list as &$v) {
				$v['time_type'] =date('Y-m-d H:i:s',$v['createtime']); 
				$v['account'] = $member->where("id = ".$v['sid'])->getField("account");
			}
			unset($v);		
			$list = array("total"=>(int)$total,"rows"=>$list);
			$this->ajaxReturn($list);
		}else {
			$this->assign('_page', $page);
			$this->assign('_rows', $listRows);
			$this->assign('now_status',$now_status); //当前页面筛选的状态
			
			// 记录当前列表页的cookie
			cookie(C('CURRENT_URL_NAME'),$_SERVER['REQUEST_URI']);
			$this->display($type);
		}
	}

	/**
	 * status 0,1 切换
	 */
	public function state($id) {
		$id = (int)$id;
	
		$model = new Model('Taobao');
		$info = $model->where("`id`=".$id)->field('id,status')->find();
		$newstate =  ($info['status'] > 0) ? '0' : '1';
		if (false === $model->where('`id`='.$id)->setField('status',$newstate)) {
			$this->error('更新失败,未知错误!');
		}
		$this->success('更新成功');
	}
}